/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package Web_service_simulation;

import Entity.Contacts;
import java.util.Date;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;

/**
 *
 * @author sabrina
 */
@Stateless
@Path("entity.contacts")
public class ContactsFacadeREST extends AbstractFacade<Contacts> {
    @PersistenceContext(unitName = "TableOnlineWSPU")
    private EntityManager em;

    public ContactsFacadeREST() {
        super(Contacts.class);
    }

    @POST
    @Override
    @Consumes({"application/xml", "application/json"})
    public void create(Contacts entity) {
        super.create(entity);
    }

    @PUT
    @Path("{id}")
    @Consumes({"application/xml", "application/json"})
    public void edit(@PathParam("id") Integer id, Contacts entity) {
        super.edit(entity);
    }

    @DELETE
    @Path("{id}")
    public void remove(@PathParam("id") Integer id) {
        super.remove(super.find(id));
    }

    @GET
    @Path("{id}")
    @Produces({"application/xml", "application/json"})
    public Contacts find(@PathParam("id") Integer id) {
        return super.find(id);
    }
    
    @GET
    @Path("country")
    @Produces({"application/xml","application/json"})
    public Contacts findCountry(@PathParam("country") String country) {
        return super.findCountry(country);
    }
    
    @GET
    @Path("updatedAt")
    @Produces({"application/xml"})
    public List<Contacts> findDate(@QueryParam("updatedAt") String updatedAt) {
        System.out.println("\n\n\n\n\n\nupdatedAt = " + updatedAt);
        return super.findNewAndUpdate(updatedAt);
    }

    @GET
    @Override
    @Produces({"application/xml", "application/json"})
    public List<Contacts> findAll() {
        return super.findAll();
    }

    @GET
    @Path("{from}/{to}")
    @Produces({"application/xml", "application/json"})
    public List<Contacts> findRange(@PathParam("from") Integer from, @PathParam("to") Integer to) {
        return super.findRange(new int[]{from, to});
    }

    @GET
    @Path("count")
    @Produces("text/plain")
    public String countREST() {
        return String.valueOf(super.count());
    }

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }
    
}
